Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
I have this Document in the database. How do I set a query in mongoose so that I can delete an object in the "cart" array

This is the post request that is supposed to delete the object in the "cart" array based on the product "id".

.post('/delete', async (req, res) => {
  if (await UserProfile.findOneAndDelete({ 'cart.id': req.body.id })) {   //This isn't woking.
     res.status(200).json({
        message: 'deleted',
     });
  } else
     res.json({
        message: 'failed',
     });

});

Suppose I want to delete the object with the name : "BEER". How do I do that

This is what the Document

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Please Try this,

db.getCollection('Test').update(
    {"cart.id" : req.body.id },
    { $pull: { cart: { name: 'BEER' } } },
    false,
    true
);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda